package site.assad.i18n;

import java.util.Locale;
import java.util.ResourceBundle;

/**
 * Author: Al-assad 余林颖
 * E-mail: yulinying_1994@outlook.com
 * Date: 2017/12/1 12:19
 * Description: 测试 ResourceBoundle
 */
public class ResourceBoundleTest {

    public static void main(String[] args){

        /*test ResourceBoundle*/
        //使用系统用默认Locale获取资源包
        Locale locale = Locale.getDefault();
        ResourceBundle resourceBundle = ResourceBundle.getBundle("site/assad/i18n/resource");
        //获取资源包中的对应键值
        String common = resourceBundle.getString("greeting.common");   //"你好!"
        String morning = resourceBundle.getString("greeting.morning");  //"早上好!"
        String afternoon = resourceBundle.getString("greeting.afternoon");  //"下午好!"
        System.out.println(common+"\n"+morning+"\n"+afternoon);

        //指定Locale获取资源包
        ResourceBundle resourceBundle2 = ResourceBundle.getBundle("site/assad/i18n/resource",Locale.US);
        String common2 = resourceBundle2.getString("greeting.common");   //"How are you!"
        System.out.println(common2);

    }
}
